package com.rainng.coursesystem.repository;

import com.rainng.coursesystem.model.FollowItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface FollowRepository extends JpaRepository<FollowItem, Integer> {  // or a suitable ID type

    boolean existsByFollowerNumberAndFollowedNumber(String followerNumber, String followedNumber);

    @Transactional
    @Modifying
    void deleteByFollowerNumberAndFollowedNumber(String followerNumber, String followedNumber);

    List<FollowItem> findByFollowerNumber(String followerNumber);

    @Query("SELECT f.followedNumber FROM FollowItem f WHERE f.followerNumber = :followerNumber")
    List<String> findFollowedNumbersByFollowerNumber(@Param("followerNumber") String followerNumber);


}